package la.iok.hzsvn.lewin.movie.core.model;

import la.iok.hzsvn.share.collection.IdAble;
import la.iok.hzsvn.share.utils.StringUtils;

import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @since 1.1.0
 */
public class MovieBase implements IdAble<Long> {
    /**
     * 在线状态常量
     */
    public static final Integer STATUS_ONLINE = 0;
    /**
     * 离线状态常量
     */
    public static final Integer STATUS_OFFLINE = 1;
    private Long id;
    /**
     * 作者
     */
    private String author;
    /**
     * 标签数组
     */
    private String[] tag;
    /**
     * 简介
     */
    private String brief;
    /**
     * 最少玩家数量
     */
    private Integer minPlayers;
    /**
     * 最大玩家数量
     */
    private Integer maxPlayers;
    /**
     * 剧本总的开本数量
     */
    private Integer playTimes;
    /**
     * 持续时长
     */
    private Float duration;
    /**
     * 状态位。0表示正常状态,1表示已经下线
     */
    private Integer status;
    /**
     * 价格。统一价。标准价,单位:分
     */
    private Integer price;
    /**
     * 剧本级别名
     */
    private String movieLevelName;

    @Override
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String[] getTag() {
        return tag;
    }

    public void setTag(String[] tag) {
        this.tag = tag;
    }

    public String getBrief() {
        return brief;
    }

    public void setBrief(String brief) {
        this.brief = brief;
    }

    public Integer getMinPlayers() {
        return minPlayers;
    }

    public void setMinPlayers(Integer minPlayers) {
        this.minPlayers = minPlayers;
    }

    public Integer getMaxPlayers() {
        return maxPlayers;
    }

    public void setMaxPlayers(Integer maxPlayers) {
        this.maxPlayers = maxPlayers;
    }

    public Integer getPlayTimes() {
        return playTimes;
    }

    public void setPlayTimes(Integer playTimes) {
        this.playTimes = playTimes;
    }

    public Float getDuration() {
        return duration;
    }

    public void setDuration(Float duration) {
        this.duration = duration;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getPrice() {
        return price;
    }

    public void setPrice(Integer price) {
        this.price = price;
    }

    public String getMovieLevelName() {
        return movieLevelName;
    }

    public void setMovieLevelName(String movieLevelName) {
        this.movieLevelName = movieLevelName;
    }

    /**
     * 判断是否在线状态
     * @return 在线状态返回true,否则false
     */
    public boolean statusOnline(){
        return STATUS_ONLINE.equals(status);
    }

    /**
     * 判断是否离线状态,是离线返回true,否则false
     * @return 是离线状态返回true,否则false
     */
    public boolean statusOffline(){
        return STATUS_OFFLINE.equals(status);
    }

    /**
     * 剧本标签转换为存储的字符串形式
     * @param tag 标签数组
     * @return 标签的存储字符串,为分号分隔的字符串
     */
    public static String storeTag(String[] tag){
        if(tag == null || tag.length == 0){
            return null;
        }
        return Arrays.stream(tag).filter(Objects::nonNull).map(String::trim).collect(Collectors.joining(";"));
    }

    /**
     * 剧本标签转换为存储的字符串形式
     * @return 标签的存储字符串,为分号分隔的字符串
     */
    public String storeTag(){
        return storeTag(tag);
    }

    /**
     * 剧本标签转换为数组形式
     * @param tag 存储的标签字符串
     * @return 标签数组
     * @see #storeTag()
     * @see #storeTag(String[])
     */
    public static String[] showTag(String tag){
        if(StringUtils.isBlank(tag)){
            return new String[0];
        }
        return tag.split(";");
    }

    /**
     * @since 1.1.1
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof MovieBase)) return false;
        MovieBase movieBase = (MovieBase) o;
        return Objects.equals(id, movieBase.id) && Objects.equals(author, movieBase.author) && Arrays.equals(tag, movieBase.tag)
                && Objects.equals(brief, movieBase.brief) && Objects.equals(minPlayers, movieBase.minPlayers)
                && Objects.equals(maxPlayers, movieBase.maxPlayers) && Objects.equals(playTimes, movieBase.playTimes)
                && Objects.equals(duration, movieBase.duration) && Objects.equals(status, movieBase.status)
                && Objects.equals(price, movieBase.price) && Objects.equals(movieLevelName, movieBase.movieLevelName);
    }

    /**
     * @since 1.1.1
     */
    @Override
    public int hashCode() {
        int result = Objects.hash(id, author, brief, minPlayers, maxPlayers, playTimes, duration, status, price, movieLevelName);
        result = 31 * result + Arrays.hashCode(tag);
        return result;
    }

    /**
     * @since 1.1.1
     */
    @Override
    public String toString() {
        return "MovieBase{" +
                "id=" + id +
                ", author='" + author + '\'' +
                ", tag=" + Arrays.toString(tag) +
                ", brief='" + brief + '\'' +
                ", minPlayers=" + minPlayers +
                ", maxPlayers=" + maxPlayers +
                ", playTimes=" + playTimes +
                ", duration=" + duration +
                ", status=" + status +
                ", price=" + price +
                ", movieLevelName='" + movieLevelName + '\'' +
                '}';
    }
}
